package com.heima.nio.bytebuffer;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

import static com.heima.nio.bytebuffer.ByteBufferUtil.*;

/**
 * 分散读取
 * @author ZhengDp
 * @Date 2023/6/22 17:29
 */
public class TestScatteringReads {
    public static void main(String[] args) {
        try(FileChannel channel = new FileInputStream("C:\\MyStudySpace\\Code\\basic-code\\netty-test\\data.txt").getChannel()) {
            ByteBuffer b1 = ByteBuffer.allocate(3);
            ByteBuffer b2 = ByteBuffer.allocate(3);
            ByteBuffer b3 = ByteBuffer.allocate(3);
            channel.read(new ByteBuffer[]{b1,b2,b3});
            b1.flip();
            b2.flip();
            b3.flip();
            debugAll(b1);
            debugAll(b2);
            debugAll(b3);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
